<?php
$baseUrl = $this->baseUrl();
?>
<form id="dataform" class="uniForm" action="javascript:submit();"
	style="padding: 0.5em 1em 1em 1.5em;">
<h2>Property Submission</h2>
<hr />
<?php
	if($this->userType != 'agnt'){
?>
<div class="ctrlHolder"><label for="name"><em>*</em>Name</label> <input
	name="name" id="name" data-default-value="e.g. Ravi Kumar Gupta"
	size="35" maxlength="50" type="text"
	class="textInput required validatePhrase" />
<p class="formHint">Full Name of Owner</p>
</div>

<div class="ctrlHolder"><label for="contact"><em>*</em>Contact Number of
Owner</label> <input name="contact" id="contact"
	data-default-value="e.g. 9896102030" size="35" maxlength="12"
	type="text" class="textInput required validateInteger" />
<p class="formHint">Contact Number of <span class="cName">Owner</span></p>
</div>

<div class="ctrlHolder"><label for="alternate_number">Alternate Contact Number (if any)</label>
<input name="alternate_number" id="alternate_number" data-default-value="e.g. 9896102030" size="35" maxlength="12"
	type="text" class="textInput validateInteger" />
<p class="formHint">Alternate Contact Number of <span class="cName">Owner</span></p>
</div>

<div class="ctrlHolder"><label for="owner_address"><em>*</em> Owners
Address</label> <textarea name="owner_address" id="owner_address"
	data-default-value="e.g. #007, Subhash colony,Faridabad" cols="10"
	rows="5" class="textInput required"></textarea>
<p class="formHint">Address of <span class="cName">Owner</span></p>
</div>
<?php
	} 
?>
<div class="ctrlHolder"><label for="category_id">Category</label> <select
	name="category_id" id="category_id" class="selectInput">
	<option value="RES" selected="selected">Residential</option>
	<option value="COM">Commercial</option>
	<option value="IND">Industrial</option>
</select>
<p class="formHint">Category of <span class="cName">Property</span></p>
</div>

<div class="ctrlHolder"><label for="type_id">Type</label> <select
	name="type_id" id="type_id" class="selectInput">
</select>
<p class="formHint">Type of <span class="cName">Propetry</span></p>
</div>

<div class="ctrlHolder"><label for="estate_for">Property is available for</label>
<select name="estate_for" id="estate_for" class="selectInput">
	<option value="SALE">Sale</option>
	<option value="RENT">Rent</option>
</select>
<p class="formHint">Status of <span class="cName">Property</span></p>
</div>

<div class="ctrlHolder"><label for="state"><em>*</em>State</label> 
	<select id="state" name="state" class="selectInput">
          		<option value="-1">Please Select</option>
				<optgroup label="Union Territory"></optgroup>
				<option value="Andaman and Nicobar Islands">Andaman and Nicobar Islands</option>
				<option value="Chandigarh">Chandigarh</option>
				<option value="Dadra and Nagar Haveli">Dadra and Nagar Haveli</option>
				<option value="Daman and Diu">Daman and Diu</option>
				<option value="Lakshadweep">Lakshadweep</option>
				<option value="Pondicherry">Pondicherry</option>
				<option value="New Delhi">New Delhi</option>
				
				<optgroup label="States"></optgroup>
				<option value="Andhra Pradesh">Andhra Pradesh</option>
				<option value="Arunachal Pradesh">Arunachal Pradesh</option>
				<option value="Assam">Assam</option>
				<option value="Bihar">Bihar</option>
				<option value="Chhattisgarh">Chhattisgarh</option>
				<option value="Goa">Goa</option>
				<option value="Gujarat">Gujarat</option>
				<option value="Haryana">Haryana</option>
				<option value="Himachal Pradesh">Himachal Pradesh</option>
				<option value="Jammu/Kashmir">Jammu and Kashmir</option>
				<option value="Jharkhand">Jharkhand</option>
				<option value="Karnataka">Karnataka</option>
				<option value="Kerala">Kerala</option>
				<option value="Madhya Pradesh">Madhya Pradesh</option>
				<option value="Maharashtra">Maharashtra</option>
				<option value="Manipur">Manipur</option>
				<option value="Meghalaya">Meghalaya</option>
				<option value="Mizoram">Mizoram</option>
				<option value="Nagaland">Nagaland</option>
				<option value="Orissa">Orissa</option>
				<option value="Punjab">Punjab</option>
				<option value="Rajasthan">Rajasthan</option>
				<option value="Sikkim">Sikkim</option>
				<option value="Tamil Nadu">Tamil Nadu</option>
				<option value="Tripura">Tripura</option>
				<option value="Uttaranchal">Uttaranchal</option>
				<option value="Uttar Pradesh">Uttar Pradesh</option>
				<option value="West Bengal">West Bengal</option>
		          	
          </select>
<p class="formHint">State of <span class="cName">Property</span></p>
</div>

<div class="ctrlHolder"><em>*</em><label for="district">District</label> <input
	name="district" id="district" data-default-value="e.g. Ambala"
	size="35" maxlength="50" type="text" class="textInput required" />
<p class="formHint">District of <span class="cName">Property</span>(if applicable)</p>
</div>

<div class="ctrlHolder"><label for="city"><em>*</em>City/Town/Village</label> <input
	name="city" id="city" data-default-value="e.g. Ambala City" size="35"
	maxlength="50" type="text" class="textInput required" />
<p class="formHint">City of <span class="cName">Property</span></p>
</div>

<div class="ctrlHolder"><label for="location"><em>*</em>Location</label> <input
	name="location" id="location" data-default-value="e.g. 365, Model Town"
	size="35" maxlength="50" type="text" class="textInput required" />
<p class="formHint">Location of <span class="cName">Property</span></p>
</div>
<div class="ctrlHolder"><label for="bhk"><em>*</em>BHK</label>
	<input name="bhk" id="bhk" value="0" size="35" maxlength="50" type="text" class="textInput validateInteger required" />
<p class="formHint">Bhk (if applicable) of <span class="cName">Property</span> in case of type FLAT.
</div>
<div class="ctrlHolder"><label for="area_unit">Area Unit</label>
	<select name="area_unit" id="area_unit" class="selectInput">
    	<option value="sqft" selected="selected">sq.ft.</option>
    	<option value="sqmeter">sq. meter</option>
    	<option value="sqyard">sq.yard</option>
    	<option value="acre">acre</option>
    	<option value="hectare">hectare</option>
    	<option value="marla">marla</option>
    </select>
	<p class="formHint">Unit to specify area.</p>
</div>

<div class="ctrlHolder"><label for="size"><em>*</em>Size</label>
	<input name="size" id="size" data-default-value="e.g. 12" size="35" maxlength="50" type="text" class="textInput validateNumber required" />
<p class="formHint">Size of <span class="cName">Property</span> in 
<span class="unitName">sq.ft.</span></p>
</div>
<div class="ctrlHolder"><label for="price"><em>*</em>Price</span></label> <input name="price"
	id="price" data-default-value="e.g. 8000" size="35"
	maxlength="50" type="text" class="textInput validateNumber required" />
<p class="formHint">Total price for <span class="cName">Property</span></p>
</div>
<div class="ctrlHolder"><label for="rate_per_unit"><em>*</em>Rate/<span
	class="unitName">sq.ft.</span></label> <input name="rate_per_unit"
	id="rate_per_unit" data-default-value="e.g. 8000" size="35"
	maxlength="50" type="text" class="textInput validateNumber required" />
<p class="formHint">Rate for <span class="cName">Property</span> in /<span class="unitName">sq.ft.</span></p>
</div>
<div class="ctrlHolder"><label for="summary"><em>*</em>Summary</label> <textarea
	name="summary" id="summary"
	data-default-value="e.g. Well furnished,24hour services,near bus stand...etc"
	rows="25" cols="25"></textarea>
<p class="formHint">Summary of <span class="cName">Property</span></p>
</div>

<div class="ctrlHolder"><label for="property_name">Property Name (if any)</label>
	<input name="property_name" id="property_name" data-default-value="e.g. Gupta House" size="35"
	maxlength="50" type="text" class="textInput" />
<p class="formHint"></p>
</div>
<?php
	
	if($this->userType == 'agnt'){
?> 
<div class="ctrlHolder"><label for="referer">Referred by</label>
	<input name="referer" id="referer" value="<?php echo strtoupper($this->user) ?>" disabled="disabled" size="35"
	maxlength="50" type="text" class="textInput" />
<p class="formHint">Mention if property is referred by a registered person.</p>
</div>
<?php
	} ?>
<br/>
<div class="buttonHolder">
<button type="submit" class="secondaryAction">Cancel and go back</button>
<button type="submit" class="primaryAction">Submit</button>
</div>
</form>
<div id="submitStatus" style="display: none;"
	class="ui-state-highlight ui-corner-all"></div>
<script>
    var urlPropertyRegister = "<?php echo $this->url(array('controller' => 'sell', 'action' => 'register'))?>";
    var estateTypes = {};
    estateTypes.RES = {flat:'Flat',villa:'Villa',plot:'Plot','bnglo':'Banglow',kothi:'Kothi'};
    estateTypes.COM = {plot:'Plot',shop:'Shop',sroom:'Showroom',cspace:'Commercial Space',cland:'Commercial Land'};
    estateTypes.IND = {iland:'Industrial Land','site':'Site'};
	
    $(function(){
        
        $('form.uniForm').uniform({
            prevent_submit : true
    	});
    	
    	updatePTypes($('#category_id').val());
    	
        $('#category_id').change(function() {
            var cat = $(this).val();
            updatePTypes(cat);
        }) ;


        $('#area_unit').change(function() {
            var aUnit = $('#area_unit :selected').text();
            $('.unitName').text(aUnit);
        });
    });


    $('#price').bind('change',function() {
    	var size = $('#size').val();
		var totalPrice = $(this).val();
		var ratePerUnit = totalPrice/size;
        $('#rate_per_unit').val(ratePerUnit).attr('disabled',true);
    });

    $('#rate_per_unit').bind('change',function() {
    	var size = $('#size').val();
		var ratePerUnit = $(this).val();
		var totalPrice = ratePerUnit*size;
		$('#price').val(totalPrice).attr('disabled',true);
    });

    
      function updatePTypes(param) {
          pType = param.toUpperCase();
          switch (pType) {
    			case 'RES' :
    			case 'COM' :
    			case 'IND' :
        			var selectString = '';
        			$.each(estateTypes[pType], function (index, name) {
        				selectString += '<option value ="'+index+'">'+name+'</option>';
        			});
        			//prepareSelectOption(jDept, selectString);
        			selectString += '</select>';
        			$('#type_id').html(selectString);
  				break;
			default :
                console.log('pType :"'+pType+'" is not in cases.');
				break;
		}
      }
		
      function submit() {
            $.ajax({
                url : urlPropertyRegister,
                data : getValues(),
                success: function(jStatus){
                    $( "#submitStatus" ).text(jStatus).show( 'blind', '', 'slow', function(){
                        alert(jStatus);
                        scroll(this);
                      	setTimeout(function(){
                          	window.location.reload();
                          	},1700);
                      } );
                  },
                    error: function(response) {
                  	  $('#errorBox').text(response.responseText).parent().show();
                        console.log(response);
                        }
                    });
            }
        function getValues() {
            var formData = {oper:'add'}; 
            $('#dataform :input')
            .not('button,:input[value^="e.g."]')
            		.each(function(){
            			formData[this.name] = this.value; 
                });
  			return formData;
  		}
        function scroll(destination){
        	var pos = $(destination).offset().top;
        	pos -= 100;
        	$('html, body').animate({
        	scrollTop: pos
        	}, 'slow');
        }
        </script>
<?php
$this->headScript()->appendFile(
$baseUrl . '/plugins/uni-form/js/uni-form-validation.jquery.js');
$this->headLink()->prependStylesheet(
$baseUrl . '/plugins/uni-form/css/uni-form.css');
$this->headLink()->prependStylesheet(
$baseUrl . '/plugins/uni-form/css/smooth.uni-form.css');
$this->headLink()->prependStylesheet(
$baseUrl . '/plugins/uni-form/demos/css/demo.css');
?>